package com.example.user.controller;


import com.example.user.common.Result;
import com.example.user.entity.Comment;
import com.example.user.service.CommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "http://localhost:8080")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping("/selectCommentPage")
    public Result<PageInfo> selectCommentPage(@RequestParam Integer activityId){
        PageHelper.startPage(1,10);
       List<Comment> commentList= commentService.selectCommentPage(activityId);
       PageInfo<Comment> pageInfo=new PageInfo<>(commentList);
       return Result.success(pageInfo);
    }


    @PostMapping("/addComment")
    public Result addComment(@RequestBody Comment comment){

       Result result= commentService.addComment(comment);
       return result;
    }
}
